%WLS_STEP --- performs a step of Weighted Least Squares (WLS) algorithm
% theta: m x 1 vector
% P: m x m matrix (symmetric)
% phi: m x 1 vector 
% y: scalar
% weight: scalar (weighting factor) [=1:LS; >1:forgetting factor; <1:WLS]
% 
function [theta_new,P_new,err_new,err_last]=WLS_step(theta,P,phi,y,weight)
err_last=y-theta'*phi;
a=1/(weight+phi'*P*phi);
theta_new=theta+a*P*phi*err_last;
P_new=P-a*P*phi*phi'*P;
err_new=y-theta_new'*phi;
